package com.china.school.controller;


import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class TestController {


    @GetMapping("/hello")
    public String hello(){

        return "hello";
    }
    @GetMapping("/error2")
    public String error(){

         return "error";
    }


    @Bean
    public BeanNameUrlHandlerMapping beanNameUrlHandlerMapping(){
        return new BeanNameUrlHandlerMapping();
    }

    @Bean
    SimpleControllerHandlerAdapter simpleControllerHandlerAdapter(){
        return new SimpleControllerHandlerAdapter();
    }


    @Bean("/world")
    public org.springframework.web.servlet.mvc.Controller controller(){
        return new org.springframework.web.servlet.mvc.Controller() {

            @Override
            public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
                ModelAndView modelAndView = new ModelAndView();
                modelAndView.setViewName("index");

                return modelAndView;
            }
        };

    }


}
